home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 3.3 KB | 101 lines | [TEXT/MPS ] |
- ;=============================================================================
- ; UMemory assembly language routines
- ;
- ; Copyright © 1987-1990 Apple Computer, Inc. All rights reserved.
- ;
- Blanks On
- String AsIs
- Case On
-
- Print Off
- Include 'Macros.a'
-
- LOAD 'ProgStrucMacs.d'
- LOAD 'FlowCtlMacs.d'
- Print On
-
-
- ;---------------------------------------------------------------------------------------------------
- ; PROCEDURE ALoadMacAppSeg;
- ; This is the actual patch for LoadSeg. It sets up the stack so that we
- ; can call FUNCTION LoadMacAppSegment (segNum: INTEGER): LONGINT.
-
- Seg 'MAMemoryRes'
- EXPORT PROCEDURE ALOADMACAPPSEG(theSegNum:W)
-
- BEGIN Save=D0-D2/A0-A2
- IMPORT LOADMACAPPSEGMENT, POSTLOADMACAPPSEGMENT
-
- CALL LOADMACAPPSEGMENT:L(theSegNum(FP):W),A0
-
- Move.W theSegNum(FP),-(SP) ; push the original parameter to loadseg
- PEA ComeBack+6 ; push a return address
- ; loadseg will knock 6 off the return address
- Jmp (A0) ; Call the original loadseg
-
- ComeBack
- CALL POSTLOADMACAPPSEGMENT ; call back to Pascal again
-
- Sub.L #6,4(FP) ; jerk our return address just like loadseg does
- ; Return ; Return to the real world
- ; the Return macro doesn't preserve the A0 register because it generates the following code
-
- ;00000026: 4CDF 0707 'L...' MOVEM.L (A7)+,D0-D2/A0-A2
- ;0000002A: 4E5E 'N^' UNLK A6
- ;0000002C: 205F ' _' MOVEA.L (A7)+,A0
- ;0000002E: 544F 'TO' ADDQ.W #$2,A7
- ;00000030: 4ED0 'N.' JMP (A0)
-
- ; So… we'll just have to take over from the computers and land this puppy by hand
-
- MOVEM.L (A7)+,D0-D2/A0-A2
- UNLK A6
- MOVE.L (A7),2(A7) ; move the return address into the place of the
- ; parameter because we will destroy the stack-frame
- ; that includes the parameter and then just RTS
- ; This assumes intimate knowledge (!) of the fact that
- ; this function only has a single parameter that is
- ; an integer (2 bytes)
- ADDQ.W #$2,A7 ; Destroy the stack frame just like I told you
- RTS ; We're outta here with A0 preserved
- EndP
-
- ;---------------------------------------------------------------------------------------------------
- ; FUNCTION PreLoadSegment;
- ; This function preloads a segment in both the resource manager sense and the
- ; segment loader sense.
-
- Seg 'MAMemoryRes'
- EXPORT FUNCTION PRELOADSEGMENT(theSegNum:W):B
-
- BEGIN Save=D0-D2/A0-A2
- IMPORT PRELOADSEGMENTRESOURCE, LOADMACAPPSEGMENT, POSTLOADMACAPPSEGMENT
- ; preload the resource so our call to the seg loader patch won't fail
-
- CALL PRELOADSEGMENTRESOURCE:B(theSegNum(FP):W),D0
- TST.B D0
- BNZ.S success
- ;segment didn't load
-
- Move.B #0, PRELOADSEGMENT(FP)
- BRA.S exit
-
-
- success
- CALL LOADMACAPPSEGMENT:L(theSegNum(FP):W),A0
-
- Move.W theSegNum(FP),-(SP) ; push the original parameter to loadseg
- PEA ComeBack+6 ; push a return address
- ; loadseg will knock 6 off the return address
- Jmp (A0) ; Call the original loadseg
-
- ComeBack
- CALL POSTLOADMACAPPSEGMENT ; call back to Pascal again
-
-
- Move.B #1, PRELOADSEGMENT(FP)
- exit
- Return ; Return to the real world
-
- END
-